package com.mentaleye.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MultipleTansferUtil {
/**
 * 
 * @param code   多选方法传入的字符串
 * @param map    可以根据编号查对应的名称
 * @return   处理后通过编号查出对应的名称，或者拼接名称
 */
	public String multipleTansfer(String code, Map<Integer, String> map) {
		String str2 = "";
		String str4 = "";
		if (code == null) {
			str2 = null;
		}else if(code == ""){
			str2 = "";
		}else if (code.contains(",")) {
			String[] list = code.split(",");
			for (String str3 : list) {
				str4 = map.get(Integer.valueOf(str3));//总经理  zhuli
				str2 += str4 + ",";//str2=总经理，   str2= zhuli,
			}
			str2 = deleteSymbol(str2);
		} else {
			str2 = map.get(Integer.valueOf(code));
		}
		return str2;
	}
	public String deleteSymbol(String str){
		String str1 = null;
		if(str.endsWith(",")){
			str1 = str.substring(0, str.length()-1);
		}
		return str1;
	}
	
	
	public static List<Integer> splitStrToList(String str){
		int str1 = 0;
		List<Integer> list = new ArrayList<Integer>();
		if(str.contains(",")){
			String[] a = str.split(",");
			for (int i = 0; i < a.length; i++) {
				str1 = Integer.valueOf(a[i]);
				list.add(str1);
			}
		}else{
			list.add(Integer.valueOf(str));
		}
		return list;
	}

	public static  String getMybatisSql(String sql){
		return  sql.replaceAll("&lt;" ,"<")
				.replaceAll("&gt;" ," >")
				.replaceAll("&amp;" ,"&")
				.replaceAll("&apos;" ,"'")
				.replaceAll("&&quot;" ,"\"");
	}
	
}
